<?php

namespace App\Http\Resources\V1;

use Illuminate\Http\Resources\Json\JsonResource;

class ArticleResource extends JsonResource
{
    public function toArray($request)
    {
        $data = [
            'id'    => $this->id,
            'title' => $this->title,
            'logo_url'      => $this->logo_url,
            'introduction'  => $this->introduction,
            'content'       => $this->content,
            'created_at'    => $this->created_at->toDateTimeString(),
        ];

        $data['cate'] = new ArticleCateResource($this->whenLoaded('cate'));
        $data['replies'] = ArticleReplyResource::collection($this->whenLoaded('replies'));

        return $data;
    }
}
